package system

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"ruoyi_gin/app/admin/model/system"
	"ruoyi_gin/utils"
)

func GetRoutersHandler(context *gin.Context) {
	userId, _ := context.Get("userId")
	var user system.SysUser
	err1 := utils.MysqlDb.Where("user_id = ?", userId).First(&user)
	if err1.Error != nil {
		context.JSON(http.StatusOK, gin.H{
			"msg":  "未找到用户",
			"code": http.StatusInternalServerError,
		})
		return
	}

	menu := system.SelectMenuTreeByUserId(utils.GetInterfaceToInt(userId))
	var data = system.BuildMenus(menu)
	context.JSON(http.StatusOK, gin.H{
		"msg":  "操作成功",
		"code": http.StatusOK,
		"data": data,
	})
}
